package com.ctshk.rpc.scenic.service.impl;

import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.scenic.dto.AirshowApiSettingDTO;
import com.ctshk.rpc.scenic.entity.AirshowApiSetting;
import com.ctshk.rpc.scenic.mapper.AirshowApiSettingMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.rpc.scenic.req.AirshowApiSettingReq;
import com.ctshk.rpc.scenic.service.IAirshowApiSettingService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-06-10
 */
@DubboService
public class AirshowApiSettingServiceImpl extends ServiceImpl<AirshowApiSettingMapper, AirshowApiSetting> implements IAirshowApiSettingService {

    @Autowired
    private AirshowApiSettingMapper airshowApiSettingMapper;

    @Override
    public Result<AirshowApiSettingDTO> getApiSetting() {

        AirshowApiSetting airshowApiSetting = airshowApiSettingMapper.selectById(59319985322852352l);

        AirshowApiSettingDTO airshowApiSettingDTO = EntityUtil.copy(airshowApiSetting, AirshowApiSettingDTO.class);

        return Result.success(airshowApiSettingDTO);
    }

    @Override
    public Result saveApiSetting(AirshowApiSettingReq airshowApiSettingReq, TokenUser tokenUser) {

        AirshowApiSetting airshowApiSetting = EntityUtil.copy(airshowApiSettingReq, AirshowApiSetting.class);

        int i = airshowApiSettingMapper.updateById(airshowApiSetting);

        if(i > 0)
            return Result.success();

        return Result.failed(SystemError.SYS_437);
    }
}
